[C#] Three System.Drawing methods manifest slow drawing or flickery: Solutions? or Other Options?

Posted by Luke Mcneice on Stack Overflow See other posts from Stack Overflow or by Luke Mcneice
Published on 2010-03-15T22:46:42Z Indexed on 2010/03/16 0:09 UTC
Read the original article Hit count: 241

Filed under:
|

Hi all,

I am doing a little graphing via the System.Drawing and im having a few problems.

I'm holding data in a Queue and i'm drawing(graphing) out that data onto three picture boxes

this method fills the picture box then scrolls the graph across.

so not to draw on top of the previous drawings (and graduly looking messier) i found 2 solutions to draw the graph.

  1. Call plot.Clear(BACKGOUNDCOLOR) before the draw loop [block commented]

although this causes a flicker to appear from the time it takes to do the actual drawing loop.

  1. call plot.DrawLine(channelPen[5], j, 140, j, 0); just before each drawline [commented]

although this causes the drawing to start ok then slow down very quickly to a crawl as if a wait command had been placed before the draw command.

Here is the Code for reference:

/*plotx.Clear(BACKGOUNDCOLOR)

ploty.Clear(BACKGOUNDCOLOR)

plotz.Clear(BACKGOUNDCOLOR)*/

for (int j = 1; j < 599; j++)
            {
                if (j > RealTimeBuffer.Count - 1) break;

                QueueEntity past = RealTimeBuffer.ElementAt(j - 1);
                QueueEntity current = RealTimeBuffer.ElementAt(j);

                if (j == 1)
                {
                    //plotx.DrawLine(channelPen[5], 0, 140, 0, 0);
                    //ploty.DrawLine(channelPen[5], 0, 140, 0, 0);
                    //plotz.DrawLine(channelPen[5], 0, 140, 0, 0);
                }

                //plotx.DrawLine(channelPen[5], j, 140, j, 0);
                plotx.DrawLine(channelPen[0], j - 1, (((past.accdata.X - 0x7FFF) / 256) + 64), j, (((current.accdata.X - 0x7FFF) / 256) + 64));

                //ploty.DrawLine(channelPen[5], j, 140, j, 0);
                ploty.DrawLine(channelPen[1], j - 1, (((past.accdata.Y - 0x7FFF) / 256) + 64), j, (((current.accdata.Y - 0x7FFF) / 256) + 64));

                //plotz.DrawLine(markerPen, j, 140, j, 0);
                plotz.DrawLine(channelPen[2], j - 1, (((past.accdata.Z - 0x7FFF) / 256) + 94), j, (((current.accdata.Z - 0x7FFF) / 256) + 94));


            }

Is there any tricks to avoid these overheads?

If not would there be any other/better solutions?

© Stack Overflow or respective owner

Related posts about c#

Related posts about system.drawing